/*
 * Copyright JiangXumin.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <ros/ros.h>
#include <gtest/gtest.h>

#include "libyaml/libyaml.hpp"
#include <iostream>


TEST(TestSuite, save_Test)
{
  Libyaml yaml("/tmp/work/config.yaml");
  yaml.load_file();
  yaml.set_origin_geo(1,2,3);
  double lan_o = 0;
  double lon_o = 0;
  double h_o = 0;
  yaml.get_origin_geo(lan_o,lon_o,h_o);
  
  EXPECT_FLOAT_EQ(1.0,lan_o);
  EXPECT_FLOAT_EQ(2.0,lon_o);
  EXPECT_FLOAT_EQ(3.0, h_o);
  /*
  ASSERT_FLOAT_EQ(1.0,lan_o);
  ASSERT_FLOAT_EQ(2.0,lon_o);
  ASSERT_FLOAT_EQ(3.0, h_o);
  */

  yaml.save_file();
}

TEST(TestSuite, writ_Test)
{
  Libyaml yaml("/tmp/work/config.yaml");
  yaml.load_file();
  double lan_o = 0;
  double lon_o = 0;
  double h_o = 0;
  yaml.get_origin_geo(lan_o,lon_o,h_o);
  
  EXPECT_FLOAT_EQ(1.0,lan_o);
  EXPECT_FLOAT_EQ(2.1,lon_o)  << "....  failed";
  EXPECT_FLOAT_EQ(3.0, h_o);

  ASSERT_FLOAT_EQ(1.0,lan_o);
  ASSERT_FLOAT_EQ(2.0,lon_o);
  ASSERT_FLOAT_EQ(3.0, h_o);

  yaml.save_file();
}

int main(int argc, char **argv)
{
  testing::InitGoogleTest(&argc, argv);
  ros::init(argc, argv, "test_libyaml");
  return RUN_ALL_TESTS();
}
